package com.xucan.breakx;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class BigDecimalFormatExample {
    public static void main(String[] args) {
        BigDecimal number1 = new BigDecimal("8");
        BigDecimal number3 = new BigDecimal("8.01");
        BigDecimal number4 = new BigDecimal("8.011");
        BigDecimal number2 = new BigDecimal("10.01");

        String formattedNumber1 = formatBigDecimal(number1);
        String formattedNumber2 = formatBigDecimal(number2);
        String formattedNumber3 = formatBigDecimal(number3);
        String formattedNumber4 = formatBigDecimal(number4);

        System.out.println(formattedNumber1);
        System.out.println(formattedNumber2);
        System.out.println(formattedNumber3);
        System.out.println(formattedNumber4);
    }

    public static String formatBigDecimal(BigDecimal number) {
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return decimalFormat.format(number);
    }
}